﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Mysoft.QuickCode.Web.EasyUI
{
    /// <summary>
    /// 树形结构返回值
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public class TreeNode<T>
    {
        public List<TreeNode<T>> children = new List<TreeNode<T>>();
        public string id { set; get; }
        public string text { set; get; }
        public string parentId { set; get; }
        public int level { set; get; }
        public string state { set; get; }
        public bool checkedStatus { set; get; }
        public string iconCls { set; get; }
        public T attribute { set; get; }
        public object attributes { set; get; }

        public void GenerateTree(List<TreeNode<T>> dataList)
        {
            List<TreeNode<T>> childList = dataList.Where(i => i.parentId == id).ToList();
            var childCount = childList.Count();
            if (childCount > 0)
            {
                if (id != "all")
                {
                    state = "closed";
                }
                children.AddRange(childList);
                foreach (TreeNode<T> t in childList)
                {
                    t.GenerateTree(dataList);
                }
            }
        }
    }
}
